var app = getApp();
Page({
  mobileInputEvent: function (e) {
    this.setData({
      omessage: e.detail.value
    })
  },
  data: {
    // input默认是1 
    num: 1,
    apiurl: app.data.apiurl,
    // gid:'',
    // gfare:'',
    // spec:'',
    // price:'',
    // gtitle:'',
    ofare:'',
    ocoupon:'',
    opaymoney:'',
    ausername:'',
    amobile:'',
    area:'',
    addresss:'',
    addobj:{},
    openid: app.globalData.openid,
    getoid:'',
    // 使用data数据对象设置样式名 
    minusStatus: 'disabled',
    redata: {},
	id:'',
	allprice:'',
	orderMsg:"",
	total_fee:''
  },
  onLoad: function (options) {
    var that=this
    that.setData({
      // gid:options.gid,
      // num:options.num,
      // spec:options.spec,
      // price: options.price,
      id: options.id,
      allprice: options.allprice
    });
    wx.setNavigationBarTitle({
      title: '订单详情'
    });
   // 获取用户地址
    wx.chooseAddress({
      
      success: function (res) {
        console.log(res);
       
        that.setData({
          addobj: res,
        // address: res.data,
          ausername: res.userName,
          amobile: res.telNumber,
          area: res.provinceName + res.cityName + res.countyName,
          addresss: res.detailInfo 
        });
        //商品详情
   
       
      }
    });
    wx.request({
      url: getApp().data.apiurl + '/index.php/index/index/placeOrder?id=' + options.id + '&openid=' + app.globalData.openid+'&allprice='+options.allprice,
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
         console.log(res.data);
        that.setData({
          redata: res.data,
          
        });
       
      }
	 
    });
   
  },
  //获取用户微信系统地址
  getAddress: function () {
    var that=this
    wx.chooseAddress({

      success: function (res) {
        console.log(res);

        that.setData({
          addobj: res,
          // address: res.data,
          ausername: res.userName,
          amobile: res.telNumber,
          area: res.provinceName + res.cityName + res.countyName,
          addresss: res.detailInfo
        });
     

      }
    });
  },
  paymoney:function(e){
    var that=this;
    //获得订单信息
	if(this.data.adress!=''){

 
    wx.request({
      url: getApp().data.apiurl + '/index.php/index/index/getshoporder?id=' + this.data.id + '&ausername=' + this.data.ausername + '&amobile=' + this.data.amobile + '&area=' + this.data.area + '&addresss=' + this.data.addresss + '&allprice=' + this.data.allprice + '&openid=' + app.globalData.openid,
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        that.goPay(res);
      }
      
    });
  }else{
    wx.showToast({
      title: '请填写地址',
      icon: 'clear',
      duration: 2000,
      image: '../../images/tanhao.png'
    });
  }
    console.log(this.data.orderMsg);

       
   
  },
  /* 点击减号 */
  bindMinus: function () {
    var num = this.data.num;
    // 如果大于1时，才可以减 
    if (num > 1) {
      num--;
    }
    // 只有大于一件的时候，才能normal状态，否则disable状态 
    var minusStatus = num <= 1 ? 'disabled' : 'normal';
    // 将数值与状态写回 
    this.setData({
      num: num,
      minusStatus: minusStatus
    });
  },
  /* 点击加号 */
  bindPlus: function () {
    var num = this.data.num;
    // 不作过多考虑自增1 
    num++;
    // 只有大于一件的时候，才能normal状态，否则disable状态 
    var minusStatus = num < 1 ? 'disabled' : 'normal';
    // 将数值与状态写回 
    this.setData({
      num: num,
      minusStatus: minusStatus
    });
  },
  /* 输入框事件 */
  bindManual: function (e) {
    var num = e.detail.value;
    // 将数值与状态写回 
    this.setData({
      num: num
    });
  },
  getTest:function(e){
    return "这是";

  },
  /**调起微信支付**/
  goPay:function(e){

    wx.request({
      url: app.data.apiurl + "/wxpay/wxpay.php?out_trade_no=" + e.data.order_sn + '&total_fee=' + e.data.total_fee + '&openid=' + app.globalData.openid,
      data: {},
      method: 'POST',
      success: function (res) {
        //console.log(res);
        //console.log('unified order success, response is:', res)
        var payargs = res.data;
        wx.requestPayment({
          timeStamp: payargs.timeStamp,
          nonceStr: payargs.nonceStr,
          package: payargs.package,
          signType: payargs.signType,
          paySign: payargs.paySign,
          'success': function () {//支付成功
            wx.switchTab({//成功后跳转
              url: '../mine/mine',
            });

          },
          'fail': function () {
            wx.showToast({
              title: '用户取消支付',
              icon: 'clear',
              duration: 5000,
              image: '../../images/tanhao.png',
              success: function () {
                wx.switchTab({
                  url: '../mine/mine',
                });
              }
            });
          }

        })
      },
    });
  }
 

})